from fastapi import APIRouter
from fastapi.encoders import jsonable_encoder
from models.Models import User
from db.DBUtil import DBUtil

router = APIRouter()


@router.get("/list/{page_index}/{page_size}")
def list_user(page_index: int, page_size: int):
    db_util = DBUtil()
    session = db_util.get_session()
    users = session.query(User).order_by(User.id).limit(page_size).offset((page_index-1)*page_size)
    db_util.close()
    return jsonable_encoder(users.all())
